package service

import (
	ClickHouse "gin/database"
	"gin/types"
)

type UserMonthWorkhour struct {
}

//var UserMonthManhourService UserMonthManhour

// GetMonthManhour 查询工时
func (receiver *UserMonthWorkhour) GetMonthManhour(where interface{}, stepCategoryIdList []uint64) (res []types.DepartmentUserDingManhour, err error) {
	err = ClickHouse.DB.Table("user_month_workhour umw").
		Joins("JOIN tenant_user tu on tu.user_id = umw.user_id JOIN department d on tu.department_id = d.id JOIN role r on r.id = tu.role_id").
		Where(where).
		Select("umw.name as user_name,umw.user_id as user_id,umw.hours as hours,umw.work_date as work_date,umw.grade as grade,umw.group_name as group_name,umw.department_name as department_name,toUInt64OrZero(arrayJoin(splitByChar(',', d.step_category_ids))) as step_category_id").
		Having("step_category_id in ?", stepCategoryIdList).
		Find(&res).Error
	return
}

// GetMonthManhourLeavePeople 查询离职人员工时
func (receiver *UserMonthWorkhour) GetMonthManhourLeavePeople(where interface{}, stepCategoryIdList []uint64) (res []types.DepartmentUserDingManhour, err error) {
	err = ClickHouse.DB.Table("user_month_workhour umw").
		Where(where).
		Select("umw.name as user_name,umw.user_id as user_id,umw.hours as hours,umw.work_date as work_date,umw.grade as grade,umw.group_name as group_name,umw.department_name as department_name,toUInt64OrZero(arrayJoin(splitByChar(',', step_category_ids))) as step_category_id").
		Having("step_category_id in ?", stepCategoryIdList).
		Find(&res).Error
	return
}
